//
//  PYScreenRotateManager.m
//  IHome
//
//   Created by zhujizheng on 2020/2/18.
//  Copyright © 2019年 com.zhujizheng. All rights reserved.
//

#import "PYScreenRotateManager.h"
@implementation PYScreenRotateConfig

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.shouldIPadAutorotate = YES;
        self.iPadSupportedInterfaceOrientations = UIInterfaceOrientationMaskAll;
        self.iPadStatusBarOrientation = UIInterfaceOrientationPortrait;

        self.shouldIPhoneAutorotate = NO;
        self.iPhoneSupportedInterfaceOrientations = UIInterfaceOrientationMaskPortrait;
//        self.shouldIPhoneAutorotate = YES;
//        self.iPhoneSupportedInterfaceOrientations = UIInterfaceOrientationMaskAll;
        self.iPhoneStatusBarOrientation = UIInterfaceOrientationPortrait;
    }
    return self;
}

@end

@interface PYScreenRotateManager ()
/**
 屏幕配置
 */
@property (nonatomic, strong) PYScreenRotateConfig *config;

@end

@implementation PYScreenRotateManager

+ (instancetype)manager
{
    static PYScreenRotateManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [PYScreenRotateManager new];
        manager.config = [PYScreenRotateConfig new];
    });
    return manager;
}

+ (BOOL)shouldAutorotate
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
        return [PYScreenRotateManager manager].config.shouldIPadAutorotate;
    } else {
        return [PYScreenRotateManager manager].config.shouldIPhoneAutorotate;
    }
}

+ (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
        return [PYScreenRotateManager manager].config.iPadSupportedInterfaceOrientations;
    } else {
        return [PYScreenRotateManager manager].config.iPhoneSupportedInterfaceOrientations;
    }
}

+ (UIInterfaceOrientation)statusBarOrientation
{
    if (UIUserInterfaceIdiomPad == UI_USER_INTERFACE_IDIOM()) {
        return [PYScreenRotateManager manager].config.iPadStatusBarOrientation;
    } else {
        return [PYScreenRotateManager manager].config.iPhoneStatusBarOrientation;
    }
}

+ (void)makeConfigWithConfig:(PYScreenRotateConfig *)screenRotateConfig
{
    if (!screenRotateConfig) {
        [PYScreenRotateManager makeDefaultConfig];
    }
    [PYScreenRotateManager manager].config = screenRotateConfig;
}

+ (void)makeDefaultConfig
{
    [PYScreenRotateManager manager].config = [PYScreenRotateConfig new];
}

#pragma mark - MLeaksFinder methods
- (BOOL)willDealloc {
    return NO;
}
@end
